package game

import (
	"fmt"
	"regexp"
	"server/csvs"
	"time"
)

type ManageBanWord struct {
	BanWordBase 	[]string	// 基础字库
	BanWordExtra 	[]string	// 扩展字库，根据用户输入学习得到的的
}

// 单例模式
var manageBanWord	*ManageBanWord

func GetManageBanWord() *ManageBanWord {
	if manageBanWord == nil {
		manageBanWord = new(ManageBanWord)
		manageBanWord.BanWordBase = []string {"外挂", "透视", "卖号"}
		manageBanWord.BanWordExtra = []string {"原神"}
	}

	return manageBanWord
}

func (self *ManageBanWord) IsBanWord (txt string) bool {
	for _, v := range self.BanWordBase{
		match, _ := regexp.MatchString(v, txt)
		if match {
			return match
		}
	}

	for _, v := range self.BanWordExtra{
		match, _ := regexp.MatchString(v, txt)
		if match {
			return match
		}
	}

	return false
}

func (self *ManageBanWord) Run()  {
	self.BanWordBase = csvs.GetBanWordbase()

	ticker := time.NewTicker(time.Second * 1)
	for {
		select {
		case <-ticker.C:
			if time.Now().Unix() % 10 == 0 {
				fmt.Println("更新词库")
			}else {
				//fmt.Println("待机状态")
			}
		}
	}
}